package com.js.mail.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.cors.reactive.CorsWebFilter;

/**
 * @author js1981725869@163.com
 * @date 2021年06月24日 00:03
 */
@Configuration
public class JsCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();

        //配置跨域
        //允许cookie跨域
        corsConfiguration.setAllowCredentials(true);
        //允许任意来源的请求
        corsConfiguration.addAllowedOrigin("*");
        //允许任意方法
        corsConfiguration.addAllowedMethod("*");
        //允许任意请求头
        corsConfiguration.addAllowedHeader("*");
        source.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsWebFilter(source);
    }
}
